package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStore.HotGoodsData;
import com.zhongxi.guoyuan.url.Url;

import java.util.List;

/**
 * Created by Administrator on 2017/4/12.
 */

public class RewardCoinListAdapter extends BaseAdapter {
    private List<HotGoodsData> data;
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public RewardCoinListAdapter(Context context, List<HotGoodsData> data) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.data = data;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.adapter_reward_coin_list, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
            holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
            holder.tvPrice = (TextView) convertView.findViewById(R.id.tvPrice);
            holder.tvView = (TextView) convertView.findViewById(R.id.tvView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=data.get(position)&&!"".equals(data.get(position))) {
            HotGoodsData list = data.get(position);
            if (null !=list.getThumbnail()&&!"".equals(list.getThumbnail())) {
                Glide.with(mContext).load(Url.IMG_URL+list.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(holder.ivImg);
            }
            if(null!=list.getName()&&!"".equals(list.getName())){
                holder.tvName.setText(list.getName());
            }else{
                holder.tvName.setText("");
            }
            if(null!=list.getSubject()&&!"".equals(list.getSubject())){
                holder.tvDesc.setText(list.getSubject());
            }else{
                holder.tvDesc.setText("");
            }
            if(null!=list.getPrice()&&!"".equals(list.getPrice())){
                holder.tvPrice.setText(list.getPrice());
            }else{
                holder.tvPrice.setText("");
            }
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvName;
        private TextView tvDesc;
        private TextView tvPrice;
        private TextView tvView;
    }
}
